package HighLevelFunction

object PattenMatch {
  def main(args: Array[String]): Unit = {
    //模式守卫
    def abs(num: Int): Int = {
      num match {
        case i if i >= 0 => i
        case i if i < 0 => -i
      }
    }

    println(abs(1))
    println(abs(-1))
    for (list <- List(
      List(0),
      List(1, 0),
      List(0, 0, 0),
      List(1, 1, 0),
      List(88)
    )) {
    val result=list match{
      case List(0)=>"0"
      case List(x,y)=>s"List(x,y):${x},${y}"
      case List(0,_*)=>"List(0,......)"
      case List(a)=>s"List(a):${a}"
      case _=>"other List"
    }
      println(result)
    }
    val list1=List(1,2,3,4,5)
    list1 match {
      case first::second::three::rest=>println(s"first:${first},second:${second},three:${three},rest:${rest}")
      case _=>println("something else")
    }
    println("==========================")
    val (x,y)=(10,"hello")
    println(s"x:${x},y:${y}")
    val fir::sec::rest=List(23,34,445,66,12)
    println(s"fir:${fir},sec:${sec},rest:${rest}")

  }

}
